/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    height: 100vh;
    overflow: hidden;
}

/* Container layout - responsive for iframe vs full screen */
.container {
    display: flex;
    width: 100%;
    height: 450px; /* Default iframe height */
    max-height: 450px;
    gap: 8px;
    padding: 8px;
}

/* Full screen mode detection */
@media (min-height: 500px) and (min-width: 1000px) {
    .container {
        height: 90vh;
        max-height: 90vh;
    }
}

/* Left Panel - Tools */
.left-panel {
    width: 200px;
    min-width: 180px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.tool-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.section-label {
    font-size: 12px;
    font-weight: 600;
    color: #555;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Button Styles */
.pen-btn, .tool-btn, .action-btn, .zoom-btn {
    border: none;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
    justify-content: center;
    min-height: 36px;
    white-space: nowrap;
}

.pen-btn {
    background: #e9ecef;
    color: #495057;
    flex: 1;
}

.pen-btn.active {
    background: #007bff;
    color: white;
    box-shadow: 0 2px 8px rgba(0, 123, 255, 0.3);
}

.tool-btn {
    background: #f8f9fa;
    color: #495057;
    flex: 1;
}

.tool-btn:hover, .pen-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.action-btn {
    background: #6c757d;
    color: white;
    width: 100%;
}

.action-btn.primary {
    background: #007bff;
}

.action-btn.success {
    background: #28a745;
}

.action-btn.danger {
    background: #dc3545;
}

.action-btn:hover {
    transform: translateY(-1px);
    opacity: 0.9;
}

.tool-group {
    display: flex;
    gap: 6px;
}

/* Controls */
.control-group {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
}

.control-group label {
    min-width: 50px;
    font-weight: 500;
}

.control-group input[type="range"] {
    flex: 1;
    height: 4px;
    background: #ddd;
    border-radius: 2px;
    outline: none;
}

.control-group span {
    min-width: 30px;
    text-align: center;
    font-weight: 600;
    color: #007bff;
}

/* Color Palette */
.color-palette {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.color-option {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s ease;
}

.color-option.active {
    border-color: #007bff;
    transform: scale(1.1);
}

.color-option:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* Zoom Controls */
.zoom-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
}

.zoom-btn {
    width: 32px;
    height: 32px;
    background: #f8f9fa;
    color: #495057;
    font-size: 16px;
    font-weight: bold;
}

#zoomLevel {
    font-size: 11px;
    font-weight: 600;
    min-width: 40px;
    text-align: center;
}

/* Canvas Container */
.canvas-container {
    flex: 1;
    position: relative;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

#mainCanvas {
    width: 100%;
    height: 100%;
    cursor: crosshair;
    display: block;
}

.animation-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 18px;
    font-weight: bold;
    z-index: 10;
    text-align: center;
}

.animation-overlay.hidden {
    display: none;
}

/* AI Generated Image Display */
.ai-generated-image {
    max-width: 90%;
    max-height: 70%;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    animation: fadeInScale 0.8s ease-out;
}

/* Loading spinner for AI generation */
.loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid #fff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes fadeInScale {
    0% {
        opacity: 0;
        transform: scale(0.8);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Right Panel */
.right-panel {
    width: 200px;
    min-width: 180px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
}

/* Gallery */
.gallery-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.gallery-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    max-height: 120px;
    overflow-y: auto;
}

.gallery-item {
    aspect-ratio: 1;
    background: #f8f9fa;
    border-radius: 6px;
    border: 2px solid #e9ecef;
    cursor: pointer;
    transition: all 0.2s ease;
    overflow: hidden;
}

.gallery-item:hover {
    border-color: #007bff;
    transform: scale(1.02);
}

.gallery-item canvas {
    width: 100%;
    height: 100%;
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Reflection */
.reflection-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
}

#reflection {
    width: 100%;
    min-height: 80px;
    padding: 8px;
    border: 2px solid #e9ecef;
    border-radius: 6px;
    font-size: 11px;
    font-family: inherit;
    resize: vertical;
    outline: none;
    transition: border-color 0.2s ease;
}

#reflection:focus {
    border-color: #007bff;
}

/* Tips Section */
.tips-section {
    margin-top: auto;
}

.tip-card {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 10px;
    border-radius: 8px;
    font-size: 11px;
    line-height: 1.4;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Center Tooltip */
.center-tooltip {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 14px;
    max-width: 300px;
    text-align: center;
    z-index: 1000;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.center-tooltip.show {
    opacity: 1;
}

.center-tooltip.hidden {
    display: none;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .container {
        flex-direction: column;
        height: 450px;
        gap: 6px;
        padding: 6px;
    }
    
    .left-panel, .right-panel {
        width: 100%;
        height: 80px;
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
    }
    
    .tool-section {
        min-width: 150px;
    }
    
    .canvas-container {
        flex: 1;
        min-height: 200px;
    }
    
    .pen-btn, .tool-btn, .action-btn {
        font-size: 10px;
        padding: 6px 8px;
        min-height: 32px;
    }
}

/* Touch-friendly targets */
@media (pointer: coarse) {
    .pen-btn, .tool-btn, .action-btn, .zoom-btn {
        min-height: 44px;
        min-width: 44px;
    }
    
    .color-option {
        width: 32px;
        height: 32px;
    }
}

/* Animation keyframes */
@keyframes bounce {
    0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-10px); }
    60% { transform: translateY(-5px); }
}